package ru.st.selenium;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.testng.*;
import org.testng.annotations.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class AddMovie extends ru.st.selenium.pages.TestBase {
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Test
  public void testAddMovie() throws Exception {
    // ERROR: Caught exception [ERROR: Unsupported command [getEval | 0 | ]]
    driver.get(baseUrl + "/php4dvd/");
    driver.findElement(By.cssSelector("img[alt=\"Add movie\"]")).click();
    driver.findElement(By.name("name")).clear();
    driver.findElement(By.name("name")).sendKeys("The Bodyguard");
    driver.findElement(By.name("aka")).clear();
    driver.findElement(By.name("aka")).sendKeys("The Bodyguard");
    driver.findElement(By.name("year")).clear();
    driver.findElement(By.name("year")).sendKeys("1992");
    driver.findElement(By.name("duration")).clear();
    driver.findElement(By.name("duration")).sendKeys("130");
    driver.findElement(By.id("formats")).clear();
    driver.findElement(By.id("formats")).sendKeys("Blu-ray");
    driver.findElement(By.name("plotoutline")).clear();
    driver.findElement(By.name("plotoutline")).sendKeys("Rachel Marron (Whitney Houston) is an Oscar-nominated music superstar who is being stalked and sent death threats. Things get dangerously out of hand when a bomb disguised as a doll explodes in her dressing room. Rachel's manager, Bill Devaney (Bill Cobbs), seeks the services of a professional bodyguard to protect her.[6] Frank Farmer (Kevin Costner) is a former Secret Service Special Agent who served as part of the presidential protection detail during the presidencies of Jimmy Carter and Ronald Reagan. Frank is haunted by the fact that he was off duty when Reagan was shot. Bill eventually finds Farmer, who is now a highly successful private bodyguard, mostly protecting corporate VIPs. However, Frank is reluctant to accept the offer to guard Rachel as he sees her as a spoiled diva who is oblivious to the threats against her life.");
    driver.findElement(By.id("text_languages_0")).clear();
    driver.findElement(By.id("text_languages_0")).sendKeys("English");
    driver.findElement(By.name("subtitles")).clear();
    driver.findElement(By.name("subtitles")).sendKeys("English");
    driver.findElement(By.name("audio")).clear();
    driver.findElement(By.name("audio")).sendKeys("English, Russian");
    driver.findElement(By.name("country")).clear();
    driver.findElement(By.name("country")).sendKeys("United States");
    driver.findElement(By.name("cast")).clear();
    driver.findElement(By.name("cast")).sendKeys("Kevin Costner\nWhitney Houston");
    driver.findElement(By.id("submit")).click();
    String url = driver.getCurrentUrl();
    System.out.println(url);
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}
